package cn.sumpu.app.coolsk.biz.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.Transactional;

import com.fivestars.interfaces.bbs.client.Client;

import cn.sumpu.app.coolsk.biz.DiscussBiz;
import cn.sumpu.app.coolsk.biz.HotelRoomBiz;
import cn.sumpu.app.coolsk.biz.IdentifierBiz;
import cn.sumpu.app.coolsk.biz.MailBiz;
import cn.sumpu.app.coolsk.biz.MemberBiz;
import cn.sumpu.app.coolsk.biz.ProductBiz;
import cn.sumpu.app.coolsk.biz.ScenicBiz;
import cn.sumpu.app.coolsk.biz.WeiboBiz;
import cn.sumpu.app.coolsk.constant.PageSize;
import cn.sumpu.app.coolsk.constant.UserType;
import cn.sumpu.app.coolsk.dao.CardNumDao;
import cn.sumpu.app.coolsk.dao.DiscussDao;
import cn.sumpu.app.coolsk.dao.KeepDao;
import cn.sumpu.app.coolsk.dao.MemberDao;
import cn.sumpu.app.coolsk.dao.PointDao;
import cn.sumpu.app.coolsk.domain.CardNum;
import cn.sumpu.app.coolsk.domain.Hotel;
import cn.sumpu.app.coolsk.domain.Keep;
import cn.sumpu.app.coolsk.domain.Member;
import cn.sumpu.app.coolsk.domain.MemberDetail;
import cn.sumpu.app.coolsk.domain.MemberTicker;
import cn.sumpu.app.coolsk.domain.OnLineUserListener;
import cn.sumpu.app.coolsk.domain.OutUser;
import cn.sumpu.app.coolsk.domain.Point;
import cn.sumpu.app.coolsk.domain.Product;
import cn.sumpu.app.coolsk.domain.Scenic;
import cn.sumpu.app.coolsk.domain.Syslog;
import cn.sumpu.app.coolsk.exception.AppBusinessException;
import cn.sumpu.toolkit.common.page.PageModel;
import cn.sumpu.toolkit.common.util.Common;
import cn.sumpu.toolkit.weibo.AccessUser;




public class MemberBizImpl implements MemberBiz{
	
	private final static Logger logger = LoggerFactory
	.getLogger(MemberBizImpl.class);

	private MemberDao memberDao;
	
	private KeepDao keepDao;
	private PointDao pointDao;
	private CardNumDao cardNumDao;
	private DiscussDao discussDao;
	@Autowired
	private HotelRoomBiz hotelRoomBiz;
	@Autowired
	private ScenicBiz scenicBiz;
	@Autowired
	private ProductBiz productBiz;
	@Autowired
	private IdentifierBiz idBiz;
	@Autowired
	private MailBiz mailBiz;
	@Autowired
	private WeiboBiz weiboBiz;
	@Autowired
	private DiscussBiz discussBiz;
	private DataSourceTransactionManager transactionManager;

	public void setTransactionManager(
			DataSourceTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	
	public void setMemberDao(MemberDao memberDao) {
		this.memberDao = memberDao;
	}
	public void setKeepDao(KeepDao keepDao) {
		this.keepDao = keepDao;
	}
	public void setPointDao(PointDao pointDao) {
		this.pointDao = pointDao;
	}
	public void setCardNumDao(CardNumDao cardNumDao) {
		this.cardNumDao = cardNumDao;
	}
	public void setDiscussDao(DiscussDao discussDao) {
		this.discussDao = discussDao;
	}
	/**
	 * 注册
	 * @param 
	 * @return
	 * @throws
	 */
	@Transactional(rollbackForClassName = { "cn.sumpu.app.coolsk.exception.AppBusinessException" }, timeout = 10)
	public Member register(String emailPath,Member member) throws AppBusinessException {
		 member.setId(idBiz.generateId("coolsk_member"));//会员号 
		 member.setActiveCode(Common.getRandStr(10, false));//邮箱激活码
		 //member.setIsActive(true);//激活邮箱
		 String salt=Common.getRandStr(6, false);
		 member.setSalt(salt);//密码MD5加密辅助字段
		 String passWord = member.getPassword();
		 member.setPassword(Common.md5(Common.md5(passWord)));
		 member.setAvatar(PageSize.AVATAR_MEMBER_DEFALUT);
		 //会员卡号注销
		 
		 regOutUser(member);  
		 memberDao.insert(member);
		 MemberDetail memberDetail=new MemberDetail();
		 memberDetail.setMemberId(member.getId());
		 memberDao.insertMemberInfo(memberDetail);
		 //记录积分
		 CardNum card =getCardNum(member.getCardNum());
		 if(card!=null){ 
			 //会员卡失效
			 card.setIsUse(false);
			 updateCardNum(card);
			 
			 Point point =new Point();
			 point.setMember(member.getId());
			 point.setRemark("注册获得2000积分");
			 point.setId(idBiz.generateId("coolsk_point"));
			 point.setPoint(2000);
			 pointDao.insertPoint(point);
			 Member memberUpdate =new Member();
			 memberUpdate.setId(member.getId());
			 memberUpdate.setCountPoint(point.getPoint());
			 update(memberUpdate);
		 } 
		mailBiz.sendEmail(emailPath, member,null,null);
		return member;
	}

	//注册外部帐号
	private void regOutUser(Member member) throws AppBusinessException {
		AccessUser accessUser=member.getAccessUser();
		 if(member.getAccessUser()!=null){
			 registerOutUser(accessUser, member.getId());
			 if(accessUser.getName()!=null){
				 member.setNickname(accessUser.getName());
			 }
			 if(accessUser.getHeadUrl()!=null){
				 member.setAvatar(accessUser.getHeadUrl());
			 }
		 }
	}
	/**
	 * 用户登陆
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member IsRegister(String loginType,String loginPwd)throws AppBusinessException {
		if (Common.empty(loginType))
			return null;
		//昵称 
		Member member = getMemberByNick(loginPwd, loginType);
		//邮箱
		if (member == null) {
			member = getMemberByEmail(loginPwd, loginType);
		}
		// 手机号码
		if (member== null) {
			member= getMemberByPhone(loginPwd, loginType);
		}
		return member;
	}
	/**
	 * 登录
	 * @author vimple
	 * @param
	 * @param
	 */
	@Override
	public String login(HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		String loginName = request.getParameter("loginName");  
		String loginPwd = request.getParameter("loginPwd");
		String autoLogin = request.getParameter("autoLogin");
		String outLoginMember = request.getParameter("om");
		try {
			// 从cookie里面直接登录
			String cookieLogin = (String) request.getSession().getAttribute("cookieLogin");
			if (Common.notEmptyStr(cookieLogin)) {
				loginName = (String) request.getSession().getAttribute("loginName");
				loginPwd = (String) request.getSession().getAttribute("loginPwd");
				request.getSession().removeAttribute("loginType");
				request.getSession().removeAttribute("loginPwd");
				request.getSession().removeAttribute("cookieLogin");
			}
			// 设置cookie
			setLoginCookie(loginName, loginPwd, autoLogin, response);
			Member  member=null;
			if(Common.notEmptyStr(outLoginMember)){
				member=getMemberById(outLoginMember);
			}else{
				member = IsRegister(loginName, loginPwd); // 是否注册会员
			} 
			if (member != null && member.getEnabled()) {
				Date loginTime=member.getLoginTime();
				String nowTime = Common.getFormatDate(Calendar.getInstance().getTime(), "yyyy-MM-dd");
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
				Date nowDate = sdf.parse(nowTime);
				Boolean isTrue =nowDate.after(loginTime);
				if(isTrue){
					//每天首次登录+5分
					int pVal=5;
					member.setCountPoint(member.getCountPoint()+pVal);
					//记录一条积分记录
					String remark="每天首次登录可获得5积分。";
					Point point =new Point();
					point.setId(idBiz.generateId("coolsk_point"));
					point.setMember(member.getId());
					point.setPoint(pVal);
					point.setRemark(remark);
					pointDao.insertPoint(point);
				}
				member.setLoginIP(request.getRemoteAddr());
				member.setLoginCount(member.getLoginCount() + 1);// 设置最后登录的次数
				member.setLoginTime(new Date());// 设置最后登录的时间
				update(member);// 设置最后登录的IP
				request.getSession(true).setAttribute("onlineUser",new OnLineUserListener(member));
				return "dailylogin";
			}else{
				return "noRegister";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 *  存储Cookie
	 * @param loginName
	 * @param loginPwd
	 * @param autoLogin
	 * @param response
	 * @throws UnsupportedEncodingException
	 */
	private void setLoginCookie(String loginName, String loginPwd, String autoLogin, HttpServletResponse response) throws UnsupportedEncodingException {
		if (Common.notEmptyStr(autoLogin)) {
			Cookie cookieLoginName = new Cookie("coolsk_user_loginName",
					URLEncoder.encode(loginName, "utf-8"));
			Cookie cookieLoginPwd = new Cookie("coolsk_user_loginPwd",
					URLEncoder.encode(loginPwd, "utf-8"));
			cookieLoginName.setMaxAge(60 * 60 * 24 * 30); // 一个月有效
			cookieLoginPwd.setMaxAge(60 * 60 * 24 * 30); // 一个月有效
			response.addCookie(cookieLoginName);
			response.addCookie(cookieLoginPwd);
		}
	}
	/**
	 * 昵称登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByNick(String pwd, String nickname)throws AppBusinessException {
		if (Common.empty(nickname))
			return null; 
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("nickname", nickname);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 邮箱登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByEmail(String pwd, String email)throws AppBusinessException {
		if (Common.empty(email))
			return null;
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("email", email);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 手机登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByPhone(String pwd, String phone)throws AppBusinessException {
		if (Common.empty(phone))
			return null;
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("mobilephone", phone);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 更新会员信息
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public void update(Member member)throws AppBusinessException {
		memberDao.update(member);
	}
	/**
	 * 验证邮箱 [注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	
	@Override
	public Member getMemberEmail(String email)throws AppBusinessException {
		if (Common.empty(email))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("email", email);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 验证昵称 [注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	
	@Override
	public Member getMemberNickName(String nickname)throws AppBusinessException {
		if (Common.empty(nickname))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nickname", nickname);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 验证手机[注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberPhone(String phone)throws AppBusinessException {
		if (Common.empty(phone))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobilephone", phone);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}

	@Override
	public AccessUser sinaLogin(String oauthVerifier)
			throws AppBusinessException {
		AccessUser accessUser=weiboBiz.requstAccessTokenSina(oauthVerifier);
		
		return accessUser;
	}

	@Override
	public String outLogin(AccessUser accessUser,HttpServletRequest request) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", accessUser.getUid()); 
		map.put("accessToken", accessUser.getAccessToken());
		map.put("accessSecret", accessUser.getAccessSecret());
		OutUser ou= memberDao.checkOutUser(map);
		
		if(ou==null){
			request.getSession(true).setAttribute("accessUser", accessUser);
			return "register";
		}else{
			request.setAttribute("outUser", ou);
			return "login";
		}
		
	}

	@Override
	public Member getMemberById(String member) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", member); 
		return memberDao.getMemberByMap(map);
	}
	
	/**
	 * 查询详细资料
	 * @param memberId
	 * @return
	 * @throws AppBusinessException
	 */
	@Override
	public MemberDetail getMemberDetailById(String memberId) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("memberId", memberId); 
		return memberDao.getMemberDetailByMap(map);
	}
	@Override
	public AccessUser tencentLogin(String oauthVerifier)
			throws AppBusinessException {
		AccessUser accessUser=weiboBiz.requstAccessTokenTencent(oauthVerifier);
		return accessUser;
	}

	@Override
	public void registerOutUser(AccessUser accessUser,String member) throws AppBusinessException {
		OutUser outUser=new OutUser();  
		outUser.setId(idBiz.generateId("coolsk_out_user"));
		outUser.setUid(accessUser.getUid());
		outUser.setMember(member);
		outUser.setAccessToken(accessUser.getAccessToken());
		outUser.setAccessSecret(accessUser.getAccessSecret());
		outUser.setEnabledSyn("t");
		String userType="";
		if(accessUser.getDesc().equals("sinaWeibo")){
			userType=UserType.SINA_WEIBO.getValue();
		}else if(accessUser.getDesc().equals("tencentWeibo")){
			userType=UserType.TENCENT_WEIBO.getValue();
		}else if(accessUser.getDesc().equals("tencentQQ")){
			userType=UserType.TENCENT_QQ.getValue();
		}
		outUser.setUserType(userType);
		memberDao.insert(outUser);
		
	}
	/**
	 * 更新资料
	 * @param memberDetail
	 * @param member
	 * @throws AppBusinessException
	 */
	@Override
	public void updateMemberDetail(MemberDetail memberDetail,Member member)throws AppBusinessException {
		memberDao.updateMemberDetail(memberDetail);
		if(memberDetail!=null){  
			member.setId(memberDetail.getMemberId());
		}  
		memberDao.update(member);
	}
	/**
	 * 添加收藏
	 */
	@Override
	public void keep(Keep keep)throws AppBusinessException {
		keep.setId(idBiz.generateId("coolsk_keep"));
		keepDao.insert(keep); 
	}
	/**查询单个收藏 判断是否收藏过
	 * 
	 */
	@Override
	public Keep getKeep(Keep keep)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("createMember", keep.getCreateMember());
		map.put("receiveOwner", keep.getReceiveOwner());
		map.put("receiveOwnerType", keep.getReceiveOwnerType());
		
		return keepDao.getKeep(map); 
	}
	/**
	 * 取消收藏
	 */
	@Override
	public void deleteKeepByid(String id)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id",id);
		keepDao.deleteKeep(map);
	}
	/**
	 * 我的收藏
	 */
	@Override
	public PageModel getKeepListByMid( Integer page,Integer pagesize, String memberId)throws AppBusinessException {
		
		Map<String, Object> map = new HashMap<String, Object>();
		int size = pagesize;
		map.put("startId", (page - 1) * size);
		map.put("pageSize", size); 
		map.put("createMember", memberId);
		int count = keepDao.getKeepCountByMid(map);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		List<Keep> keepList = keepDao.getKeepListByMid(map);
		//收藏对象的详细信息
		if(keepList.size()>0){
			for(Keep keepOne:keepList){
				String type =keepOne.getReceiveOwnerType();
				//酒店
				if(type.equals("hotel")){
					
					Hotel hotel =hotelRoomBiz.getHotelById(keepOne.getReceiveOwner());
					if(hotel!=null){
						keepOne.setOwnerName(hotel.getName());
						keepOne.setImage(hotel.getImage1());
						keepOne.setLat(hotel.getLat());
						keepOne.setLng(hotel.getLng());
					}
				//产品
				}else if(type.equals("product")){
					Product product =productBiz.getProductById(keepOne.getReceiveOwner());
					if(product!=null){
						keepOne.setOwnerName(product.getName());
						keepOne.setImage(product.getImage1());
						keepOne.setLat(product.getLat());
						keepOne.setLng(product.getLng());
					}
				//景点
				}else if(type.equals("att")){   
					Scenic scenic =scenicBiz.getScenicById(keepOne.getReceiveOwner());
					if(scenic!=null){
						keepOne.setOwnerName(scenic.getName());
						keepOne.setImage(scenic.getImage1());
						keepOne.setLat(scenic.getLat());
						keepOne.setLng(scenic.getLng());
					}
				}
				
			}
			pm.setList(keepList);
			pm.setPageSize(size);
			pm.setTotalRecord(count);
			pm.setTotalPage((count + size - 1) / size);
			return pm;
		}
		return null;
	}
	@Override
	public CardNum getCardNum(String cardNum)throws AppBusinessException {
		if (Common.empty(cardNum))
			return null; 
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("value", cardNum);
		map.put("isUse", true);
		CardNum card = cardNumDao.getCardNumByMap(map);
		return card;
	}
	//更新会员卡号
	@Override
	public void updateCardNum(CardNum cardNum)throws AppBusinessException {
		 cardNumDao.updateCardNum(cardNum);
	}
	
	//我的积分
	@Override
	public PageModel getPointListByMid( Integer page,Integer pagesize, String memberId)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		int size = pagesize;
		map.put("startId", (page - 1) * size);
		map.put("pageSize", size);
		map.put("member", memberId);
		int count =pointDao.getPointCountByMid(map);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		List<Point> pointList = pointDao.getPointListByMid(map);
		pm.setList(pointList);
		pm.setPageSize(size);
		pm.setTotalRecord(count);
		pm.setTotalPage((count + size - 1) / size);
		return pm;
	}
	//添加点评
	
	/*@Override
	public void instertDiscuss(Discuss discuss)throws AppBusinessException {
		discuss.setId(idBiz.generateId("coolsk_discuss"));
		discussDao.insert(discuss);
		//酒店的平均值
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ownerType", discuss.getOwnerType());
		map.put("owner", discuss.getOwner());
		Discuss avgDiscussByMap = discussDao.selectAvgDisByMap(map);
	}*/
	//我的点评
	@Override
	public PageModel getDisListByMid( Integer page,Integer pagesize, String memberId)throws AppBusinessException {
		return discussBiz.getAllDiscuss(page,pagesize,memberId);
	}

	@Override
	public Boolean checkMemberLogin(HttpServletRequest request)
			throws AppBusinessException {
		OnLineUserListener onLineUser=(OnLineUserListener)request.getSession().getAttribute("onlineUser");
		
		if(Common.empty(onLineUser)){
			return false;
		}else{
			if(onLineUser.getMember()==null){
				return false;
			}else{
				return true;
			}
			
		}
	}
	/**
	 * 添加取票人
	 */
	@Override
	public void insterMemberTicker(MemberTicker memberTicker)throws AppBusinessException {
		memberDao.insterMemberTicker(memberTicker); 
	}
	/**
	 * 更新取票人
	 * 
	 */
	//
	@Override
	public void updateMemberTicker(MemberTicker memberTicker)throws AppBusinessException {
		memberDao.updateMemberTicker(memberTicker); 
	}
	/**
	 * 查询取票人LIst
	 */
	@Override
	public List<MemberTicker> getTickerListById(String memberId)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		int size=5;
		map.put("memberId", memberId);
		map.put("size", size);
		return memberDao.getTickerListById(map); 
	}
	/**
	 * 
	 */
	@Override
	public void deleteTicker(String id)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		memberDao.deleteTicker(map); 
	}
	
	/**
	 * author BruceZhang
	 * @param nickname		用户昵称
	 * @param startTime		注册时间段
	 * @param endTime
	 * @return	查询用户列表
	 * @throws AppBusinessException
	 */
	@Override
	public PageModel getMemberList(String nickname, String startTime, String endTime, Integer pageSize, Integer page) throws Exception {
		if (page == null || page < 1) {
			page = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nickname", nickname);
		map.put("startTime", Common.parseDate(startTime, "yyyy-MM-dd HH:mm:ss"));
		map.put("endTime", Common.parseDate(endTime, "yyyy-MM-dd HH:mm:ss"));
		map.put("pageSize", pageSize);
		map.put("startId", (page - 1) * pageSize);
		List<Member> memberList = memberDao.getMemberList(map);
		Integer count = getMemberListCount(nickname, startTime, endTime);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		pm.setList(memberList);
		pm.setPageSize(pageSize);
		pm.setTotalRecord(count);
		pm.setTotalPage((count + pageSize - 1) / pageSize);
		return pm;
	}
	//查询用户列表总条数
	@Override
	public Integer getMemberListCount(String nickname, String startTime,
			String endTime) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nickname", nickname);
		map.put("startTime", Common.parseDate(startTime, "yyyy-MM-dd HH:mm:ss"));
		map.put("endTime", Common.parseDate(endTime, "yyyy-MM-dd HH:mm:ss"));
		return memberDao.getMemberListCount(map);
	}
	
//	public static void main(String[] args) throws ParseException {
//	//SimpleDateFormat secTime = new SimpleDateFormat("HH:mm:ss"); 
//	Date nowTime =Calendar.getInstance().getTime();
//    //Date startTime = secTime.parse("17:01:01");
//    /*Calendar c = Calendar.getInstance();
//    int year = c.get(Calendar.YEAR);
//    int month = c.get(Calendar.MONTH);
//    int day = c.get(Calendar.DATE);
//    int hour = c.get(Calendar.HOUR_OF_DAY);
//    //c.setTime(startTime);
//    c.set(Calendar.YEAR, year);
//    c.set(Calendar.MONTH, month);
//    c.set(Calendar.DATE, day);
//    c.set(Calendar.HOUR_OF_DAY, hour);
//    String date =c.getTime().toString();*/
//		String nowTime = Common.getFormatDate(Calendar.getInstance().getTime(), "yyyy-MM-dd");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
//		Date nowDate = sdf.parse(nowTime);
 //   System.out.println(nowDate);
//}
	
}
